<span class="glyphicon glyphicon-map-marker" aria-hidden="true" style="position: absolute; top: 27px; left: 45px;">
    <span>商户系统</span> /
    <span>商品管理</span> /
    <span>编辑商品分类</span>
</span>
<row>
    <div class="col-md-8 col-md-offset-2"  style="margin-top: 37px;margin-left: 5px;">
        <form class="form-horizontal" id="form">
            <div  class="form-group">
                <label for="type_id" class="col-md-3 control-label">
                    <div class="text-center">商品分类父类</div>
                </label>
                <div class="col-md-9">
                    <select class="form-control" id="type_id" name="type_id">
                        <option value="0">请选择</option>
                        {volist name="list" id="vo"}
                        {php} if($vo['id'] != $goods_type['id']) { {/php}
                            {php} if($goods_type['type_id'] == $vo['id']){ {/php}
                            <option value="{$vo.id}" selected >{$vo.title}</option>
                            {php} } else { {/php}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {php} } {/php}
                        {php} } {/php}
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="title" class="col-md-3 control-label">
                    <div class="text-center">商品分类名称</div>
                </label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="title"
                           name="title" value="{$goods_type.title}" placeholder="商品分类名称">
                </div>
            </div>
            <div class="form-group">
                <label for="logo" class="col-md-3 control-label">
                    <div class="text-center">商品类型图</div>
                </label>
                <div class="col-md-9">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test1" style="background-color: #5bb75b;">上传图片</button>
                        <span style="color: #aaaaaa;">建议像素：80px*80px</span>
                        <br /><br />
                        <div class="gs_cont_img" style="width: 100px; height: auto;">
                            {if condition="$goods_type.UploadLogo != null"}
                            <input type="hidden" id="logo" name="logo" value="{$goods_type.logo}" />
                            <img src="__IMG__/{$goods_type.UploadLogo.path}" id="image" width="100%" style="display:inline;" />
                            {else /}
                            <input type="hidden" id="logo" name="logo" value="0" />
                            <img src="__IMG__/1.png" id="image" width="100%" style="display:inline;" />
                            {/if}
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="sort" class="col-md-3 control-label">
                    <div class="text-center">排序顺序</div>
                </label>
                <div class="col-md-9">
                    <input type="number" class="form-control" id="sort" name="sort"
                           step="1" min="0" value="{$goods_type.sort}"  placeholder="排序顺序">
                </div>
            </div>
            <div class="form-group save-btn" style="">
                <a href="javascript:add()" class="ncap-btn-big ncap-btn-green"
                   style="background-color: #00a0e9;">提交</a>
                <a href="{:url('admin/GoodsType/index')}" class="ncap-btn-big ncap-btn-green"
                   style="background-color: #ff0055;">返回</a>
            </div>
        </form>
    </div>
</row>
<script type="text/javascript">
    function add() {
        var type_id = document.getElementById("type_id").value;
        var title = $("input[id='title']").val();
        var logo = $("input[id='logo']").val();
        var sort = $("input[id='sort']").val();
        if(title == ""){
            msg("请输入商品分类的名称");
            return;
        }
        if(logo == 0){
            return msg("请选择上传图片");
        }
        if(sort <= 0){
            sort = 255;
        }
        var json = {title:title,logo:logo,sort:sort,type_id:type_id,id:'{$goods_type.id}'};
        $.ajax({
            type:"POST",
            url:"{:url('Admin/GoodsType/edit')}",
            data:json,
            success:function (res) {
                msg(res);
                if(res == "编辑成功"){
                    document.getElementById("form").reset();
                    setTimeout("GoodsType()",1500);
                    return;
                }
                if(res == "请重新登录"){
                    setTimeout("location_href()",1500);
                }
            }
        });
    }
    function GoodsType() {
        window.location.href = "{:url('Admin/GoodsType/Index')}";
    }
</script>